import Mock from 'mockjs'
import avatars from './imgs/avatars.js'
import bqbs from './imgs/bqbs.js';

const getRandomInt = (min, max) => {
    // 包括 min 和 max  
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

// 聊天房间
export const chatRoomList = () => {
    const roomList = []
    const randIndex = getRandomInt(1, 3)
    for (let i = 0; i < 60; i++) {
        roomList.push({
            id: `chat-room-${i + 1}`,
            top: false,
            name: Mock.Random.cname(),
            type: 1, // 1是个人聊天 2是群聊
            avatar: avatars[i],
            noMessage: Mock.Random.integer(0, 10),
            lastMessage: {
                id: Mock.Random.string('lower', 5),
                content: Mock.Random.csentence(),
                time: Mock.Random.date(),
                type: 1,
                from: 1
            }
        })
    }
    return roomList
}

// 所有的聊天记录
export const allChatRecords = () => {
    const roomList = []
    for (let i = 0; i < 60; i++) {
        roomList.push({
            roomId: `chat-room-${i + 1}`,
            sendName: '',
            avatar: '',
            message: '2024年10月5号 13:21',
            refMessage: 0,
            type: 0, // 0是文本消息 1是图片消息 2是语音消息 3是视频消息
            img: '',
            volice: '',
            video: '',
            time: Mock.Random.date(),
        })
        const name = Mock.Random.cname();
        for (let j = 0; j < 60; j++) {
            const bqbIndex = getRandomInt(0, 10)
            // 时间消息
            if([19, 28, 34, 55].indexOf(j)>-1) {
                roomList.push({
                    id: Mock.Random.string('lower', 10),
                    roomId: `chat-room-${i + 1}`,
                    sendName: '',
                    avatar: '',
                    message: `2024年10月5号 13:${j}`,
                    refMessage: 0,
                    type: 0, // 0是文本消息 1是图片消息 2是语音消息 3是视频消息
                    img: '',
                    volice: '',
                    video: '',
                    time: Mock.Random.date(),
                })
            }
            // 图片消息
            if([3, 8, 16, 22, 36, 45, 52, 58].indexOf(j)>-1) {
                roomList.push({
                    id: Mock.Random.string('lower', 10),
                    roomId: `chat-room-${i + 1}`,
                    sendName: j % 2 === 0 ? '你的头发乱了哦' : name,
                    avatar: j % 2 === 0 ? "" : avatars[i],
                    message: '',
                    refMessage: 0,
                    type: 1, // 0是文本消息 1是图片消息 2是语音消息 3是视频消息
                    img: bqbs[bqbIndex],
                    volice: '',
                    video: '',
                    time: Mock.Random.date(),
                })
            }
            // 文本消息
            roomList.push({
                id: Mock.Random.string('lower', 10),
                roomId: `chat-room-${i + 1}`,
                sendName: j % 2 === 0 ? '你的头发乱了哦' : name,
                avatar: j % 2 === 0 ? "" : avatars[i],
                message: Mock.Random.csentence(),
                refMessage: 0,
                type: 0, // 0是文本消息 1是图片消息 2是语音消息 3是视频消息
                img: '',
                volice: '',
                video: '',
                time: Mock.Random.date(),
            })
        }
    }
    return roomList
}

/**
 * 发送消息
 * @param {房间ID} roomId 
 * @param {聊天信息} message 
 * @param {发送名称} sendName 
 */
export const insertMessage = (roomId, message, sendName) => {
    return {
        id: Mock.Random.string('lower', 10),
        roomId: roomId,
        sendName: sendName,
        avatar: "",
        message: message,
        refMessage: 0
    }
}